package com.ailk.kbi.kbirazor.component
{
	import mx.controls.Alert;
	import mx.graphics.SolidColorStroke;
	
	import spark.components.Group;
	import spark.primitives.Line;
	
	
	public class LinkLine extends Group{
		private var _xFrom:Number = -1;
		private var _xTo:Number = -1;
		private var _yFrom:Number = -1;
		private var _yTo:Number = -1;
		
		
		private var lineVertical:Line;
		private var lineHorizontal:Line;
		private var lineArrow1:Line;
		private var lineArrow2:Line;
		
		public function LinkLine()
		{
			super();
			lineVertical = new Line();  
			lineVertical.stroke = new SolidColorStroke(0x006da3,2); 
			
			lineHorizontal = new Line();  
			lineHorizontal.stroke = new SolidColorStroke(0x006da3,2); 
			this.addElement(lineHorizontal);
			
			lineArrow1 = new Line();  
			lineArrow1.stroke = new SolidColorStroke(0x006da3,1); 
			this.addElement(lineArrow1);
			
			lineArrow2 = new Line();  
			lineArrow2.stroke = new SolidColorStroke(0x006da3,1); 
			this.addElement(lineArrow2);
		}
		
		public function set xFrom(value:Number):void
		{
			if (value != _xFrom)
			{
				_xFrom = value;
				updateDisplay();
			}
		}
		
		public function get xFrom():Number
		{
			return _xFrom;
		}
		
		public function set xTo(value:Number):void
		{        
			if (value != _xTo)
			{
				_xTo = value;
				updateDisplay();
			}
		}
		
		public function get xTo():Number
		{
			return _xTo;
		}
		
		public function set yFrom(value:Number):void
		{
			if (value != _yFrom)
			{
				_yFrom = value;
				updateDisplay();
			}
		}
		
		public function get yFrom():Number
		{
			return _yFrom;
		}
		
		public function set yTo(value:Number):void
		{        
			if (value != _yTo)
			{
				_yTo = value;
				updateDisplay();
			}
		}
		
		public function get yTo():Number
		{
			return _yTo;
		}
		
		private function updateDisplay():void{			
			if(_xFrom == -1 || _xTo == -1 || _yFrom == -1 || _yTo==-1){
				return;
			}
			
			if(_yFrom != _yTo){
				this.addElement(lineVertical);
				with(lineVertical){
					xFrom=xTo=0;
					if(_yFrom < _yTo){
						yFrom=0;
						yTo=_yTo - _yFrom;				
					}
					else{
//						yFrom=_yFrom - _yTo + 4;
//						yTo=4;
						yFrom=_yFrom - _yTo;
						yTo=0;
						
					}
				}
			}
			else{
				this.removeElement(lineVertical);
				lineVertical.xFrom = 0;
				lineVertical.xTo = 0;
				lineVertical.yFrom = 0;
				lineVertical.yTo = 0;			
			}
			
			with(lineHorizontal){
				yFrom = yTo = lineVertical.yTo;
				xFrom=0;
				xTo= _xTo - _xFrom -1;
			}
			
			with(lineArrow1){
				xFrom=lineHorizontal.xTo - 4;
				xTo=lineHorizontal.xTo;
				yFrom=lineVertical.yTo - 4;
				yTo=lineVertical.yTo;
			}
			
			with(lineArrow2){
				xFrom=lineHorizontal.xTo - 4;
				xTo=lineHorizontal.xTo;
				yFrom=lineVertical.yTo + 4;
				yTo=lineVertical.yTo;
			}
		}
	}
}